var table;
layui.use(['table','laydate'], function(){
    table = layui.table;
    let laydate = layui.laydate;
    var $=layui.$;//使用内置jquery
    var layer = layui.layer; //弹层
    laydate.render({
        elem: '#signTime'
    });


    table.render({
        elem: '#test'
        ,id:'dataListTable'
        ,url:'/logisticsSign/selectAll'
        ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
        ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
            title: '提示'
            ,layEvent: 'LAYTABLE_TIPS'
            ,icon: 'layui-icon-tips'
        }]
        ,title: '用户数据表'
        ,cols: [[
            {type: 'checkbox', fixed: 'left'}
            ,{field:'signId', title:'ID', width:150, fixed: 'left', unresize: true, sort: true}
            ,{field:'orderId', title:'订单号', width:150, edit: 'text', unresize: true, sort: true}
            ,{field:'signRecipients', title:'收件人', width:150, edit: 'text'}
            ,{field:'signTime', title:'送达时间', width:150, edit: 'text'}
            ,{field:'signArea', title:'存放地点', width:200,edit: 'text'}
            ,{field:'signTel', title:'收件人电话',width:150,edit: 'text'}
            ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:200}
        ]]
        ,page: true
    });

    //头工具栏事件
    table.on('toolbar(test)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event){
            case 'getAdd':
               /* var data = checkStatus.data;
                console.info(data);*/
                layer.open({
                    type: 2,
                    area: ['600px', '400px'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: '/pages/signfor/html/signAdd.html'
                });
                break
            //自定义头工具栏右侧图标 - 提示
            case 'LAYTABLE_TIPS':
                layer.alert('这是工具栏右侧自定义的一个图标按钮');
                break;
        };
    });

    //监听行工具事件
    table.on('tool(test)', function(obj){
        var data = obj.data;
        //console.log(obj)
        if(obj.event === 'del'){
            layer.confirm('真的删除行么', function(index){
                // obj.del();
                let url="/logisticsSign/delete";
                let date ={id:data.signId};
                console.info(date);
                $.ajax({
                    type: 'delete',
                    url: url,
                    data: date,
                    dataType: 'json',
                    success: function (response) {
                        if (response.state ==1){
                            table.reload('dataListrece');
                            //父页面提示信息
                            layer.msg("删除成功");
                        }else {
                            layer.msg('删除失败');
                        }
                    }
                })
                layer.close(index);
            });
        } else if(obj.event === 'update'){
            layer.open({
                type: 2,
                area: ['600px', '400px'],
                fixed: false, //不固定
                maxmin: true,
                content: '/pages/signfor/html/signAdd.html?id='+data.signId,
            });
        }
    });
    $('#queery').on("click",function () {
        var date_={
            signRecipients:$("#signRecipients").val(),
            signTime:$("#signTime").val(),
            signTel:$("#signTel").val()
        };
        table.reload('dataListTable', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,where: date_  //需要传到后台的参数
        });
    })


    function getQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
});